<template>
    <view class="body" style="width: 100%;padding: 20rpx 20rpx 110rpx;overflow: auto;">
        <view v-if="showCheckQuality">
            <view style="padding: 16rpx 10rpx;">{{checkQualityInfoMsg}}</view>
            <view style="position: fixed;width: 100%;bottom: 0;left:0;padding: 40rpx 0;background:#FFFFFF;display: flex">
                <button type="warn" style="width: 560rpx; height: 60rpx; line-height: 60rpx; font-size: 30rpx;border-radius: 30rpx;background: #CA171D;" @click.stop="confirm('noCheck')">确定</button>
            </view>
        </view>
        <view v-else>
            <view style="width: 100%;background-color: #f7f8fa;padding: 16rpx 10rpx;margin-bottom: 10rpx;border-radius:6rpx;">
                <u-collapse-item ref="checkTaskInfo" :open="true">
                    <text slot="title" class="u-page__title">检测任务信息</text>
                    <view class="u-collapse-content">
                        <view style="padding:0 20rpx 20rpx">
                            <view class="common-list-ex" style="height: 60rpx;background-color: #efefef;margin-bottom: 0">
                                <label style="width: 34%;height: auto;padding-left: 10rpx;font-size: 28rpx;">检测任务编号:</label>
                                <text class="common-list-text-ex" style="text-align: right;padding-right: 10rpx;">{{checkTaskInfo.taskId}}</text>
                            </view>
                            <view class="common-list-ex" style="height: 60rpx;margin-bottom: 0">
                                <label style="width: 34%;height: auto;padding-left: 10rpx;font-size: 28rpx;">检测任务明细id:</label>
                                <text class="common-list-text-ex" style="text-align: right;padding-right: 10rpx;">{{checkTaskInfo.taskDetailId}}</text>
                            </view>
                            <view class="common-list-ex" style="height: 60rpx;background-color: #efefef;margin-bottom: 0">
                                <label style="width: 34%;height: auto;padding-left: 10rpx;font-size: 28rpx;">项目编码:</label>
                                <text class="common-list-text-ex" style="text-align: right;padding-right: 10rpx;">{{checkTaskInfo.prjCode}}</text>
                            </view>
                            <view class="common-list-ex" style="height: auto;margin:4rpx 0;font-size: 28rpx">
                                <view style="width: 28%;height: auto;padding-left: 6rpx;white-space: nowrap">出库明细编号:</view>
                                <view style="width: 72%;text-align: right;padding-right: 6rpx;word-break: break-all">{{checkTaskInfo.osDetailId}}</view>
                            </view>
                            <view class="common-list-ex" style="height: auto;margin:4rpx 0;font-size: 28rpx;background-color: #efefef;">
                                <view style="width: 30%;height: auto;padding-left: 6rpx;white-space: nowrap">检测机构名称:</view>
                                <view style="width: 70%;text-align: right;padding-right: 6rpx;word-break: break-all">{{checkTaskInfo.checkName}}</view>
                            </view>
                            <view class="common-list-ex" style="height: 60rpx;margin-bottom: 0">
                                <label style="width: 34%;height: auto;padding-left: 10rpx;font-size: 28rpx;">检测机构联系人:</label>
                                <text class="common-list-text-ex" style="text-align: right;padding-right: 10rpx;">{{checkTaskInfo.contact}}</text>
                            </view>
                            <view class="common-list-ex" style="height: 60rpx;background-color: #efefef;margin-bottom: 0">
                                <label style="width: 40%;height: auto;padding-left: 10rpx;font-size: 28rpx;">检测机构联系方式:</label>
                                <text class="common-list-text-ex" style="text-align: right;padding-right: 10rpx;">{{checkTaskInfo.contactDetail}}</text>
                            </view>
                            <view class="common-list-ex" style="height: auto;margin-bottom: 0;font-size: 28rpx;">
                                <label style="width: 34%;height: auto;padding-left: 10rpx;font-size: 28rpx;">送检地址:</label>
                                <text style="width:66%;text-align: right;padding-right: 6rpx;word-break: break-all">{{checkTaskInfo.contactAddress}}</text>
                            </view>
                        </view>
                    </view>
                </u-collapse-item>
                <u-collapse-item ref="checkMaterial" :open="true">
                    <text slot="title" class="u-page__title">检测物资</text>
                    <view class="u-collapse-content">
                        <view style="padding:0 20rpx 20rpx">
                            <view class="common-list-ex" style="background-color: #efefef;">
                                <label style="width: 34%;height: auto;padding-left: 10rpx;font-size: 28rpx;">物料编码:</label>
                                <text class="common-list-text-ex" style="text-align: right;padding-right: 10rpx;">{{checkTaskInfo.categoryCode}}</text>
                            </view>
                            <view class="common-list-ex" style="height: auto">
                                <label style="width: 34%;height: auto;padding-left: 10rpx;font-size: 28rpx;">物料名称:</label>
                                <text class="common-list-text-ex" style="text-align: right;padding-right: 10rpx;word-break: break-all;">{{checkTaskInfo.categoryName}}</text>
                            </view>
                            <view class="common-list-ex" style="background-color: #efefef;">
                                <label style="width: 34%;height: auto;padding-left: 10rpx;font-size: 28rpx;"><text class="colorRed">*</text>有无实物:</label>
                                <view class="common-list-text-ex" style="text-align: right;padding-right: 10rpx;">
                                    <label class="radio" style="margin-right: 10px;">
                                        <radio value="1" :checked="checkTaskInfo.physical==='1'" style="transform:scale(0.8);" :color="themeColor"/>有
                                    </label>
                                    <label class="radio">
                                        <radio value="0" :checked="checkTaskInfo.physical!=='1'" disabled=true style="transform:scale(0.8)" :color="themeColor"/>无
                                    </label>
                                </view>
                            </view>
                            <view class="common-list-ex">
                                <label style="width: 34%;height: auto;padding-left: 10rpx;font-size: 28rpx;"><text class="colorRed">*</text>退库类型:</label>
                                <view class="common-list-text-ex" style="text-align: right;padding-right: 10rpx;">
                                    {{checkTaskInfo.refundName}}
                                    <image src="/static/imges/down.png" mode="" style="width: 32rpx;height: 32rpx;top: 6rpx"></image>
                                </view>
                            </view>
                            <view class="common-list-ex" style="background-color: #efefef;">
                                <label style="width: 34%;height: auto;padding-left: 10rpx;font-size: 28rpx;"><text class="colorRed">*</text>退库数量:</label>
                                <text class="common-list-text-ex" style="text-align: right;padding-right: 10rpx;">{{checkTaskInfo.quAmount}}</text>
                            </view>
                            <view class="common-list-ex" v-if="+checkTaskInfo.rtwl === 0">
                                <label style="width: 34%;height: auto;padding-left: 10rpx;font-size: 28rpx;"><text class="colorRed">*</text>物流公司名称:</label>
                                <input style="font-size: 28rpx;background-color: #ffffff;padding-right:10rpx;text-align: right" class="common-list-inpur-ex" v-model="checkTaskInfo.shippingName" placeholder="请输入"/>
                            </view>
                            <view class="common-list-ex" style="background-color: #efefef;" v-if="+checkTaskInfo.rtwl === 0">
                                <label style="width: 34%;height: auto;padding-left: 10rpx;font-size: 28rpx;"><text class="colorRed">*</text>物流单号:</label>
                                <input style="font-size: 28rpx;background-color: #efefef;padding-right:10rpx;text-align: right" class="common-list-inpur-ex" v-model="checkTaskInfo.shippingId" placeholder="请输入"/>
                            </view>
                            <view class="common-list-ex" style="height: auto" v-if="+checkTaskInfo.rtwl === 0">
                                <label style="width:40%;height: auto;padding-left: 10rpx;font-size: 28rpx;"><text class="colorRed">*</text>送检样品信息表:</label>
                                <view class="common-list-text-ex" style="display: flex;justify-content: flex-end;padding-left: 0">
                                    <view style="width: 90rpx;height: 60rpx;border: 2rpx solid #ddd;display: flex;justify-content: center;align-items: center" @click.stop="upload" v-if="showUploadImg">
                                        <image src="/static/imges/shangchuantupian.png" mode=""
                                               style="width: 26rpx;height: 26rpx;"></image>
                                    </view>
                                    <view v-else style="display: flex;">
                                        <view style="flex:1;color: #4D88FF;line-height: 64rpx;text-decoration: underline;word-break: break-all;text-align: right;" @click.stop="download()">
                                            {{checkTaskInfo.docName}}
                                        </view>
                                        <image src="/static/imges/x.png" style="width: 32rpx;height: 32rpx;top: 16rpx;padding-left: 10rpx" @click="deleteFile()"></image>
                                    </view>
                                </view>
                            </view>
                            <view style="background-color: #efefef;padding: 20rpx" v-if="materialCodeList.length>0 || scanNum>0">
                                <view style="display: flex;justify-content: space-between">
                                    <view style="color: #333333">物资签码合集(待扫码数：<span>{{scanNum}}</span>)</view>
                                    <view style="display: flex;justify-content: flex-end">
                                        <view style="background-color: #e64340;color: #fff;padding: 0 16rpx;border-radius: 8rpx" @click.stop="refresh()">刷新</view>
                                        <view style="margin-left: 15rpx;background-color: #e64340;color: #fff;padding: 0 16rpx;border-radius: 8rpx" @click.stop="scanCode" v-if="scanNum>0">扫码</view>
                                    </view>
                                </view>
                                <view style="color: #333333">
                                    <view style="display: flex;">
                                        <view style="width: 38%">资源资产编码</view>
                                        <view style="width: 38%;text-align: center">标签ID</view>
                                        <view style="width: 24%;text-align: center">扫码状态</view>
                                    </view>
                                    <view style="display: flex;" v-for="(item,index) in materialCodeList" :key="index">
                                        <view style="width: 38%;overflow: hidden">{{item.resourceAssetCode}}</view>
                                        <view style="width: 38%;overflow: hidden;text-align: center">{{item.labelId}}</view>
                                        <view style="width: 24%;display: flex;align-items: center;justify-content: center" v-if="item.labelId">
                                            <image src="/static/imges/success.png" style="width: 32rpx;height: 32rpx;" v-if="+item.scanStatus===1"></image>
                                            <image src="/static/imges/warn.png" style="width: 32rpx;height: 32rpx;" v-else></image>
                                        </view>
                                    </view>
                                </view>
                            </view>
                        </view>
                    </view>
                </u-collapse-item>
            </view>
            <view style="position: fixed;width: 100%;bottom: 0;left:0;padding: 40rpx 0;background:#FFFFFF;display: flex">
                <button type="warn" style="width: 190rpx; height: 60rpx; line-height: 60rpx; font-size: 30rpx;border-radius: 30rpx;background: #CA171D;" @click.stop="submit()">提交</button>
                <button type="warn" style="width: 190rpx; height: 60rpx; line-height: 60rpx; font-size: 30rpx;border-radius: 30rpx;background: #FFFFFF;color: #CA171D;border:2rpx solid #CA171D;" @click.stop="backup()">驳回</button>
            </view>
        </view>
        <u-picker mode="multiSelector" v-model="showSelectType" :default-selector='defaultSelector' :range="multiSelector" @columnchange="columnChange" @confirm="confirmSelector"></u-picker>
        <view style="width: 100vw;height: 100vh;background: rgba(58, 58, 58, 0.5);position: fixed;top: 0;left: 0;display: flex;align-items: center;justify-content: center" v-if="showModalBack">
            <view style="background: #FFFFFF;width: 80%;padding: 20rpx 30rpx;border-radius: 10rpx">
                <view style="font-size: 30rpx;font-weight: bold;text-align: center;">驳回意见</view>
                <view style="padding: 20rpx;border: 2rpx solid rgba(228, 228, 228)">
                    <textarea v-model="remark" placeholder="请输入" :count="true" maxlength="50" style="height: 160rpx;font-size: 28rpx;"/>
                </view>
                <view style="margin-top:20rpx;display: flex">
                    <button type="warn" style="width: 170rpx; height: 60rpx; line-height: 60rpx; font-size: 30rpx;border-radius: 30rpx;background: #FFFFFF;color: #CA171D;border:2rpx solid #CA171D;" @click.stop="cancel()">取消</button>
                    <button type="warn" style="width: 170rpx; height: 60rpx; line-height: 60rpx; font-size: 30rpx;border-radius: 30rpx;background: #CA171D;" @click.stop="confirm('check')">确定</button>
                </view>
            </view>
        </view>
    </view>
</template>

<script>

export default {
  components: {
  },
  data() {
    return {
        checkTaskInfo:{},
        themeColor:'#CA171D',
        showSelectType:false,
        multiSelector: [
            ['附件','照片'],
            []
        ],
        scanNum:0,//待扫码数
        defaultSelector:[0],
        showUploadImg:true,
        showFileName:false,
        remark:'',
        showModalBack:false,
        materialCodeList:[],
        materialNoCodeList:[],
        taskDetailId:'',
        showCheckQuality:true,
        checkQualityInfoMsg:'',
        docSize:0,
        login:{
            acctId:'',
            token:''
        },
        processInstID:'',//实例id
    }
  },
  onLoad(option) {
      this.processInstID=option.processInstID;
      this.login.token=option.token;
      this.login.acctId=option.acctId;
      this.getSysToken();
  },

  onReady() {
      this.getTaskDetailId();
  },
  methods: {
      getSysToken(){
         this.$axios.post('/material/api/app/login/a4login',this.login).then((res)=>{
             if(res.data.insideToken){
                 uni.setStorageSync("sysToken", res.data.insideToken)
             }
         })
      },
      //获取任务详细编码
      getTaskDetailId(){
          const params={
              processInstID:this.processInstID,
          }
          this.$axios.get("/material/api/quality/retreat/processInstID2taskDetailId", params).then((res)=>{
              if(res.data){
                  this.taskDetailId=res.data;
                  this.checkQualityInfo();
              }
          })
      },
      //校验送检信息接口
      checkQualityInfo(){
          const params={
              taskDetailId:this.taskDetailId,
          }
          this.$axios.post("/material/api/quality/retreat/checkQualityInfo", params,{hideMessage:true}).then(()=>{
              this.showCheckQuality=false;
              this.getQualityInfo();
          }).catch((e)=>{
              console.log(e)
              this.showCheckQuality=true;
              this.checkQualityInfoMsg=e.message;
          })
      },
      //查询送检信息
      getQualityInfo(){
          const params={
              taskDetailId:this.taskDetailId,
          }
          this.$axios.post("/material/api/quality/retreat/queryQualityInfo", params).then((res)=>{
              this.checkTaskInfo=res.data;
              this.getQualityDetail();
              this.$nextTick(()=>{
                  this.$refs.checkTaskInfo.init();
                  this.$refs.checkMaterial.init();
              })
          })
      },
      //查询送检信息编码
      getQualityDetail(){
          this.materialCodeList=[];
          this.materialNoCodeList=[];
          const params={
              qualityId:this.checkTaskInfo.qualityId,
              prjId:this.checkTaskInfo.prjId,
              quAmount:this.checkTaskInfo.quAmount,
              taskDetailId:this.checkTaskInfo.taskDetailId,
              osDetailId:this.checkTaskInfo.osDetailId,
          }
          this.$axios.post("/material/api/quality/retreat/queryQualityDetail", params).then((res)=>{
              if(res.data){
                  res.data.data.forEach((item)=>{
                      if(item.resourceAssetCode && item.labelId){
                          this.materialCodeList.push({...item,scanStatus:0})
                      }else{
                          this.materialNoCodeList.push({...item})
                      }
                  })
                  this.scanNum=res.data.needScanLabeltotalAmount;  //待接口修改之后,直接拿接口返回的
                  this.$nextTick(()=>{
                      this.$refs.checkMaterial.init();
                  })
              }
          })
      },
      //点击上传按钮
      upload(){
          this.showSelectType = true
      },
      // 回调参数为包含columnIndex、value、values
      confirmSelector(e) {
          this.showSelectType = false
          if(JSON.stringify(e)=== JSON.stringify([0])){
              console.log('附件')
              this.chooseFile();
          }else if(JSON.stringify(e)=== JSON.stringify([1,1])){
              console.log('相册')
              this.getSelectImg();
          }else{
              console.log('相机')
              this.getCamera();
          }
      },
      //级联选择器切换时数据动态改变
      columnChange(e){
          let arr1=[
              ['附件','照片'],
              ['相机','相册']
          ]
          let arr2=[
              ['附件','照片'],
              []
          ]
          this.defaultSelector= e.column === 0 && e.index === 0 ? [0] : [1]
          this.multiSelector = e.column === 0 && e.index === 0 ? JSON.parse(JSON.stringify(arr2)) : JSON.parse(JSON.stringify(arr1))
      },
      //调用MOA拍照,相机
      getCamera() {
          imp.iCamera.open(
              {
                  quality: 84, //图片质量
                  encodingType: imp.iCamera.EncodingType.JPEG, //图片格式
              },
              (successData) => {
                  const base64Top = 'data:image/jpg;base64,';
                  this.docSize = this.dataURLtoFile(base64Top + successData.originalData)?.size;
                  console.log('文件大小：',this.docSize);
                  this.uploadFileImg(base64Top + successData.originalData,'image')
              },
              (err) => {
                  console.log('error',err)
                  uni.showModal({
                      title: '温馨提示',
                      content: "相机调用失败",
                      showCancel: false,
                      confirmColor: '#eb4b4b',
                  });
              }
          );
      },
      dataURLtoFile(dataurl) {
          let arr = dataurl.split(',');
          let mime = arr[0].match(/:(.*?);/)[1];
          let bstr = atob(arr[1]);
          let n = bstr.length;
          let u8arr = new Uint8Array(n);
          while (n--) {
              u8arr[n] = bstr.charCodeAt(n);
          }
          return new File([u8arr], {
              type: mime,
          });
      },
      //调用MOA相册
      getSelectImg() {
          // const option = {
          //     quality: 84,
          //     encodingType: imp.iCamera.EncodingType.JPEG,
          //     sizeLimit: 1024 * 2,
          //     num: 1,
          // };
          // const failed = (info) => {
          //     uni.showModal({
          //         title: '温馨提示',
          //         content: "相册调用失败",
          //         showCancel: false,
          //         confirmColor: '#eb4b4b',
          //     });
          // };
          // const success = (info) => {
          //     const base64Top = 'data:image/jpg;base64,'
          //     setTimeout(() => {
          //         for (let i = 0; i < info.length; i++) {
          //             this.docSize = this.dataURLtoFile(base64Top + info[i].thumbnailData)?.size;
          //             console.log('文件大小：',this.docSize);
          //             this.uploadFileImg(base64Top + info[i].thumbnailData,'image')
          //         }
          //     }, 300);
          //
          // };
          // imp.iCamera.select(option, success, failed);
          uni.chooseFile({
              count: 1,
              type: 'image',
              success: (res) => {
                  const tempFilePaths = res.tempFilePaths;
                  this.docSize = res.tempFiles[0].size;
                  console.log('文件大小：',this.docSize);
                  this.uploadFileImg(tempFilePaths[0],'image')
              },
              fail: (error)=>{
                  console.log(2222,error)
              }
          })
      },
      //将相机、相册图片进行上传
      uploadFileImg(url,type) {
          uni.uploadFile({
              url: process.uniEnv.commonPMS20 + "/attachment/api/attachment/file/commonUpload",
              filePath: url,
              name: 'file',
              header: {
                  'sysToken': uni.getStorageSync("sysToken"),
              },
              success: (uploadFileRes) => {
                  const response=JSON.parse(uploadFileRes.data);
                  if(response.code==='000000'){
                      this.checkTaskInfo.docName=response.data[0].file_name;
                      this.checkTaskInfo.docId=response.data[0].file_id;
                      this.checkTaskInfo.docUrl=response.data[0].http_url;
                      this.checkTaskInfo.docType = type==='file'?'1':'2';
                      this.showUploadImg=false;
                      this.$nextTick(()=>{
                          this.$refs.checkMaterial.init();
                      })
                  }else{
                      uni.showModal({
                          title: "温馨提示",
                          content: response.message,
                          confirmColor:'#eb4b4b',
                          showCancel: false
                      })
                  }

              }
          });
      },
      deleteFile(){
          this.checkTaskInfo.docName='';
          this.checkTaskInfo.docId='';
          this.checkTaskInfo.docUrl='';
          this.checkTaskInfo.docType = '1';
          this.docSize=0;
          this.showUploadImg=true;
          this.$nextTick(()=>{
              this.$refs.checkMaterial.init();
          })
      },
      //打开文件选择，并上传
      chooseFile(){
          uni.chooseFile({
              count: 1,
              type: 'file',
              success: (res) => {
                  const tempFilePaths = res.tempFilePaths;
                  this.docSize = res.tempFiles[0].size;
                  console.log('文件大小：',this.docSize);
                  this.uploadFileImg(tempFilePaths[0],'file')
              },
              fail: (error)=>{
                  console.log(2222,error)
              }
          })
      },
      // 是否是120.52开头的
      checkIpStartsWith(url) {
          // 使用正则表达式从URL中提取IP地址
          const ipRegex = /(\d{1,3}\.){3}\d{1,3}/;
          const match = url.match(ipRegex);

          if (match && match.length > 0) {
              const ip = match[0];
              // 检查IP地址是否以"120.52"开头
              return ip.startsWith('120.52');
          }

          // 如果没有找到IP地址，返回false或根据需要处理
          return false;
      },
      // 转为端口号
      changeHostPort(url) {
          let obj = {
              "120.52.40.57:15336": "192.168.53.243:7356",
              "120.52.40.57:15310": "192.168.53.42:8762",
              "120.52.40.57:15309": "192.168.53.41:8762",
              "120.52.40.57:15308": "192.168.53.40:8762",
              "120.52.40.57:15307": "192.168.53.39:8762",
              "120.52.40.57:15306": "192.168.53.38:8762",
              "120.52.40.57:15305": "192.168.53.37:8762",
              "120.52.40.57:15304": "192.168.53.37:8761",
              "120.52.40.57:15335": "192.168.53.39:8761",
              "120.52.40.57:15334": "192.168.53.38:8761"
          }
          // 提取原始URL中的host部分
          const hostRegex = /^https?:\/\/([^\/]+)/;
          const match = url.match(hostRegex);
          if (!match) return url; // 如果没有找到host部分，则返回原始URL

          const originalHost = match[1];

          // 在映射对象中找到对应的替换host
          const mappedHost = obj[originalHost];
          if (!mappedHost) return url; // 如果没有找到映射，则返回原始URL

          // 替换URL中的host部分
          return url.replace(originalHost, mappedHost);
      },
      //下载按钮
      download(){
          let url = this.checkIpStartsWith(this.checkTaskInfo.docUrl) ? this.changeHostPort(this.checkTaskInfo.docUrl) : this.checkTaskInfo.docUrl
          imp.iFile.download({
              url: url,
              saveName:this.checkTaskInfo.docName,
              autoOpen:true
          },function (data){
              if(data.status == 1){
                  console.log('下载成功')
              }else{
                  console.log('下载失败')
              }
          })
      },
      //驳回
      backup(){
          this.showModalBack=true;
      },
      //取消
      cancel(){
          this.showModalBack=false;
          this.remark=''
      },
      //驳回意见确认
      confirm(type){
          if(type==='check' && !this.remark){
              uni.showModal({
                  title: '提示',
                  content: "请输入驳回意见",
                  showCancel: false,
                  confirmColor: '#eb4b4b',
              })
              return;
          }
          const params={
              taskDetailId:this.taskDetailId,
              rejectOpinion:type==='check'?this.remark:this.checkQualityInfoMsg,
          }
          this.$axios.post("/material/api/quality/retreat/qualityInfoDisapprove", params).then(()=>{
              uni.showModal({
                  title: '提示',
                  content: "驳回成功",
                  showCancel: false,
                  confirmColor: '#eb4b4b',
                  success: () => {
                      uni.navigateBack({
                          delta: 1
                      });
                  }
              })
          }).finally(()=>{
              this.showModalBack=false;
          })
      },
      //刷新按钮
      refresh(){
          const list=this.materialCodeList.concat(this.materialNoCodeList);
          this.$axios.post("/material/api/quality/retreat/refreshQualityAssetList", list).then((res)=>{
              let listArr=[]
              let noList=[]
              res.data.forEach((item)=>{
                  if(item.resourceAssetCode && item.labelId){
                      listArr.push({
                          ...item,
                          scanStatus:item.scanStatus || 0,
                      })
                  }else{
                      noList.push({...item})
                  }
              })
              this.materialCodeList=JSON.parse(JSON.stringify(listArr))
              this.materialNoCodeList=JSON.parse(JSON.stringify(noList))
              this.$nextTick(()=>{
                  this.$refs.checkMaterial.init();
              })
          })
      },
      //扫码
      scanCode(){
          if(this.scanNum===0){
              uni.showModal({
                  title: "温馨提示",
                  content: '当前物资已全部进行扫码',
                  confirmColor:'#eb4b4b',
                  showCancel: false
              })
          }else{
              imp.iBarCode.scan((result) => {
                  //直接调用接口
                  console.log('扫码结果',result)
                  let flag=this.materialCodeList.some((item)=>{return item.labelId === result})
                  if(flag){
                      this.getScanCode(result,'exist')
                  }else{
                      // let status=this.materialCodeList.some((item)=>{return +item.scanStatus===0})
                      // if(status){
                      //     uni.showModal({
                      //         title: "温馨提示",
                      //         content: '请先对当前物资签码合集中数据进行扫码',
                      //         confirmColor:'#eb4b4b',
                      //         showCancel: false
                      //     })
                      // }else{
                      //     this.getScanCode(result,'new')
                      // }
                      this.getScanCode(result,'new')
                  }
              });
          }
      },
      getScanCode(labelId,type){
          const params={
              qualityId:this.checkTaskInfo.qualityId,
              labelId:labelId,
              osDetailId:this.checkTaskInfo.osDetailId,
          }
          this.$axios.post('/material/api/quality/retreat/scanResource',params).then((res)=>{
              if(type === 'exist'){
                  this.materialCodeList.forEach((item)=>{
                      if(item.resourceAssetCode === res.data.resourceAssetCode){
                          item.scanStatus = 1
                      }
                  })
              }else{
                  this.materialCodeList.push({...res.data,scanStatus:1})
                  this.$nextTick(()=>{
                      this.$refs.checkMaterial.init();
                  })
              }
              this.scanNum=this.scanNum-1;
          })
      },
      getCheckResult(data,type){
          return new Promise((resolve,reject) => {
              if(+this.checkTaskInfo.rtwl===0 && !data){
                  uni.showModal({
                      title: "温馨提示",
                      content: type==='shippingName'?'请填写物流公司名称！':type==='shippingId'?'请填写物流单号！':'请填写送检样品信息表!',
                      confirmColor:'#eb4b4b',
                      showCancel: false
                  })
                  reject('fail')
              }else{
                  resolve('success')
              }
          });
      },
      async submit(){
          await this.getCheckResult(this.checkTaskInfo.shippingName,'shippingName');
          await this.getCheckResult(this.checkTaskInfo.shippingId,'shippingId');
          await this.getCheckResult(this.checkTaskInfo.docName,'docName');
          // let flag=this.materialCodeList.some((item)=>{return +item.scanStatus===0})
          if(this.scanNum!==0){
              //有签有码物资是否已经进行扫码操作
              uni.showModal({
                  title: '温馨提示',
                  content: "请对物资进行扫码操作！",
                  confirmColor:'#eb4b4b',
                  showCancel: false,
              })
          }else{
              const list=this.materialCodeList.concat(this.materialNoCodeList);
              const params={
                  qualityId: this.checkTaskInfo.qualityId,
                  docType: this.checkTaskInfo.docType,
                  docId: this.checkTaskInfo.docId,
                  docName: this.checkTaskInfo.docName,
                  docUrl: this.checkTaskInfo.docUrl,
                  submitSampleInfoSize:this.docSize,
                  shippingName: this.checkTaskInfo.shippingName,
                  shippingId: this.checkTaskInfo.shippingId,
                  assetList:list,
              }
              this.$axios.post('/material/api/quality/retreat/saveQualityInfo',params).then(()=>{
                  uni.showModal({
                      title: '提示',
                      content: "提交成功",
                      showCancel: false,
                      confirmColor: '#eb4b4b',
                      success: () => {
                          uni.navigateBack({
                              delta: 1
                          });
                      }
                  })
              })
          }
      }
  },
}
</script>
<style>@import "@/common/common-ui.css";</style>
<style>@import "@/common/uView.css";</style>
<style scoped lang="scss">

</style>
